#ifndef _MFS_ISCSI_H_
#define _MFS_ISCSI_H_

typedef enum tag_MFS_ISCSI_ERR_E{
	MFS_ISCSI_SUCCESS			= 0,
	/* Generic error */
	MFS_ISCSI_ERR			= 1,
	/* session could not be found */
	MFS_ISCSI_ERR_SESS_NOT_FOUND	= 2,
	/* Could not allocate resource for operation */
	MFS_ISCSI_ERR_NOMEM			= 3,
	/* Transport error caused operation to fail */
	MFS_ISCSI_ERR_TRANS			= 4,
	/* Generic login failure */
	MFS_ISCSI_ERR_LOGIN			= 5,
	/* Error accessing/managing iSCSI DB */
	MFS_ISCSI_ERR_IDBM			= 6,
	/* Invalid argument */
	MFS_ISCSI_ERR_INVAL			= 7,
	/* Connection timer exired while trying to connect */
	MFS_ISCSI_ERR_TRANS_TIMEOUT		= 8,
	/* Generic internal iscsid failure */
	MFS_ISCSI_ERR_INTERNAL		= 9,
	/* Logout failed */
	MFS_ISCSI_ERR_LOGOUT		= 10,
	/* iSCSI PDU timedout */
	MFS_ISCSI_ERR_PDU_TIMEOUT		= 11,
	/* iSCSI transport module not loaded in kernel or iscsid */
	MFS_ISCSI_ERR_TRANS_NOT_FOUND	= 12,
	/* Permission denied */
	MFS_ISCSI_ERR_ACCESS		= 13,
	/* Transport module did not support operation */
	MFS_ISCSI_ERR_TRANS_CAPS		= 14,
	/* Session is logged in */
	MFS_ISCSI_ERR_SESS_EXISTS		= 15,
	/* Invalid IPC MGMT request */
	MFS_ISCSI_ERR_INVALID_MGMT_REQ	= 16,
	/* iSNS service is not supported */
	MFS_ISCSI_ERR_ISNS_UNAVAILABLE	= 17,
	/* A read/write to iscsid failed */
	MFS_ISCSI_ERR_ISCSID_COMM_ERR	= 18,
	/* Fatal login error */
	MFS_ISCSI_ERR_FATAL_LOGIN		= 19,
	/* Could ont connect to iscsid */
	MFS_ISCSI_ERR_ISCSID_NOTCONN	= 20,
	/* No records/targets/sessions/portals found to execute operation on */
	MFS_ISCSI_ERR_NO_OBJS_FOUND		= 21,
	/* Could not lookup object in sysfs */
	MFS_ISCSI_ERR_SYSFS_LOOKUP		= 22,
	/* Could not lookup host */
	MFS_ISCSI_ERR_HOST_NOT_FOUND	= 23,
	/* Login failed due to authorization failure */
	MFS_ISCSI_ERR_LOGIN_AUTH_FAILED	= 24,
	/* iSNS query failure */
	MFS_ISCSI_ERR_ISNS_QUERY		= 25,
	/* iSNS registration/deregistration failed */
	MFS_ISCSI_ERR_ISNS_REG_FAILED	= 26,
	/* operation not supported */
	MFS_ISCSI_ERR_OP_NOT_SUPP		= 27,
	/* device or resource in use */
	MFS_ISCSI_ERR_BUSY			= 28,

	/* Always last. Indicates end of error code space */
	MFS_ISCSI_MAX_ERR_VAL,
}MFS_ISCSI_ERR_E;

typedef enum tag_MFS_ISCSI_DIS_TYP_E
{
	MFS_ISCSI_DIS_TYPE_SENDTARGETS,
	MFS_ISCSI_DIS_TYPE_ISNS,
	MFS_ISCSI_DIS_TYPE_SLP,
	MFS_ISCSI_DIS_TYPE_FW,
    MFS_ISCSI_DIS_TYPE_MAX,
}MFS_ISCSI_DIS_TYPE_E;

#define MFS_ISCSI_MAX_RECS_NUM  (10)
#define MFS_ISCSI_IP_MAX_LEN        (256)
#define MFS_ISCSI_TGNAME_MAX_LEN    (256)
typedef enum tag_MFS_ISCSI_NODE_STARTUP_TYPE_E
{
    MFS_ISCSI_NODE_STARTUP_TYPE_MANUAL,
    MFS_ISCSI_NODE_STARTUP_TYPE_AUTOMATIC,
    MFS_ISCSI_NODE_STARTUP_TYPE_ONBOOT,
    MFS_ISCSI_NODE_STARTUP_TYPE_MAX,
}MFS_ISCSI_NODE_STARTUP_TYPE_E;

typedef enum tag_MFS_ISCSI_NODE_AUTH_TYPE_E
{
    MFS_ISCSI_NODE_AUTH_TYPE_NONE,
    MFS_ISCSI_NODE_AUTH_TYPE_CHAP,
    MFS_ISCSI_NODE_AUTH_TYPE_MUT_CHAP,
}MFS_ISCSI_NODE_AUTH_TYPE_E;

#define MFS_ISCSI_MAX_AUTH_STR_LEN  (256)
typedef struct tag_MFS_ISCSI_NODE_AUTH_INFO_S
{
    MFS_ISCSI_NODE_AUTH_TYPE_E auth_type;
    char    username[MFS_ISCSI_MAX_AUTH_STR_LEN];
    char    password[MFS_ISCSI_MAX_AUTH_STR_LEN];;
    char    username_in[MFS_ISCSI_MAX_AUTH_STR_LEN];
    char    password_in[MFS_ISCSI_MAX_AUTH_STR_LEN];
}MFS_ISCSI_NODE_AUTH_INFO_S;

typedef struct tag_MFS_ISCSI_TARGET_REC_S
{
    char    ip[MFS_ISCSI_IP_MAX_LEN];
    char    targetname[MFS_ISCSI_TGNAME_MAX_LEN];
    int     port;
    int     tpgt;
    MFS_ISCSI_NODE_AUTH_TYPE_E auth_type;
    MFS_ISCSI_NODE_AUTH_INFO_S auth_info;
    MFS_ISCSI_NODE_STARTUP_TYPE_E startup_type;
}MFS_ISCSI_TARGET_REC_S;

#endif //_MFS_ISCSI_H_

int mfs_iscsi_login_onboot_nodes(void);
int mfs_iscsi_discovery(char *server_ip, int port, MFS_ISCSI_DIS_TYPE_E discovery_type);
int mfs_iscsi_delete_node(char *server_ip, int port, char *targetname);
int mfs_iscsi_login(char *server_ip, int port, char *targetname);
int mfs_iscsi_logout(char *server_ip, int port, char *targetname);
int mfs_iscsi_set_startup_type(char *server_ip, int port, char *targetname, MFS_ISCSI_NODE_STARTUP_TYPE_E type);
int mfs_iscsi_obtain_all_rec(MFS_ISCSI_TARGET_REC_S *mfs_recs);
int mfs_iscsi_obtain_all_session(MFS_ISCSI_TARGET_REC_S *mfs_recs);

